fix(spa): smart-route action redirect URLs (#620) + release 1.4.13#643
Merged
Conversation
….4.13 A ModelAdmin action that returns ``HttpResponseRedirect(some_url)`` was looking silently no-op'd to the operator: the click ran, the toast didn't appear, and nothing visible happened. The diagnosis in the issue blamed the API for swallowing the response, but the API correctly extracts ``response["Location"]`` into the JSON envelope's ``redirect`` field (``api/views/actions.py:256``). The actual bug was on the SPA: ``DetailPage`` piped the redirect URL straight into React Router's ``navigate`` — which is scoped to the SPA's ``BrowserRouter`` ``basename``, so any URL outside the SPA mount silently no-op'd: - legacy admin paths (``/admin/<app>/<model>/<pk>/change/``) - hijack / impersonate URLs (``/hijack/release-user/?next=…``) - cross-origin downloads (signed S3 URLs) New ``followActionRedirect`` helper (`apps/web/src/action-redirect.ts`) picks the right primitive per URL: ``navigate`` for same-origin paths inside the SPA mount (no full reload), ``window.location.assign`` for everything else. Returns a stripped basename-relative path to the navigate call so BrowserRouter doesn't double-prefix. The helper is dependency-injected (``currentOrigin``, ``assignLocation``) so the test suite can lock the routing logic without touching jsdom's non-configurable ``window.location``. Locks: 6 new vitests in `action-redirect.test.ts` cover the SPA- internal path, search + hash preservation, the legacy-admin path, cross-origin URLs, the hijack pattern, and a malformed-URL fallback. Release 1.4.13 bundles this with the unreleased changes since 1.4.12 (all already merged on main): - #631 / PR #641 — ``PRIMARY_COLOR`` reads ``site_primary_color`` off the configured ``AdminSite`` before falling back to the setting + default. - #626 / PR #642 — ``raw_id_fields`` and ``radio_fields`` now render their intended widgets (plain-pk text input + lookup link, inline radio bank) instead of falling through to autocomplete / ``<select>``. - #623 / #624 / #633 / #634 / #635 — README "Stock-Django hooks that do NOT carry through" / "Writing safe ``list_display`` callables" / "Hardening" / "Mounting the API on a different origin" sections (PR #640). - PR #638 — ``release.yml`` → ``publish.yml`` rename so PyPI's Trusted Publisher config matches the workflow filename. Closes #620. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #620. Also tags v1.4.13 to ship every change accumulated on main since v1.4.12.
#620 — what actually broke
A ModelAdmin action that returns
HttpResponseRedirect(some_url)was silently no-op'd from the operator's POV. The issue blamed the API for swallowing the response, but the API correctly extractsresponse["Location"]into the JSON envelope'sredirectfield (api/views/actions.py:256). The real bug was SPA-side:DetailPagepipedredirectstraight into React Router'snavigate— scoped to the SPA'sBrowserRouterbasename, so any URL outside the SPA mount silently failed:/admin/<app>/<model>/<pk>/change/)/hijack/release-user/?next=…)Fix
New
followActionRedirecthelper picks the right primitive per URL:navigate(no full reload, basename-relative path)window.location.assign(full browser navigation)Helper is dependency-injected (
currentOrigin,assignLocation) so tests can lock the routing logic without touching jsdom's non-configurablewindow.location.What else lands in 1.4.13
All already merged on main since 1.4.12:
PRIMARY_COLORreadssite_primary_coloroff the configuredAdminSitefirst.raw_id_fields+radio_fieldswidget hints now render their intended controls.list_displaycallables, hardening (django-axes), cross-origin (CORS + cookies).release.yml→publish.ymlrename for PyPI Trusted Publisher config alignment.Verification
action-redirect.test.tscover SPA-internal path, search + hash preservation, legacy-admin path, cross-origin URL, hijack pattern, malformed URL.pnpm test— 187 / 187 ✓ (up from 181 / 181)pnpm -r typecheck✓pnpm lint✓pnpm -w build✓🤖 Generated with Claude Code